package com.lsy.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.lsy.entity.Flowrecord;
import com.lsy.mapper.interf.FlowrecordMapper;
import com.lsy.service.interf.FlowRecordService;

@Service
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class FlowRecordServiceImpl implements FlowRecordService {

	private final int NUMBER = 10;

	@Autowired
	private FlowrecordMapper flowRecordMapper;

	public boolean save(Flowrecord object) throws RuntimeException {
		boolean result = false;
		if (flowRecordMapper.insert(object) > 0) {
			result = true;
		}
		return result;
	}
	
	public int findTotalByUserId(int userId) {
		return flowRecordMapper.findTotalByUserId(userId);
	}

	public List<Flowrecord> findByUserId(int userId, int page) {
		int from = (page - 1) * NUMBER;
		return flowRecordMapper.findByUserId(userId, from, NUMBER);
	}

	public int getNumber() {
		return this.NUMBER;
	}

}
